package org.example.contract.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.contract.domain.ContractFile;
import org.example.contract.service.IContractFileService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同附件Controller
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-04-11
 */
@Controller
@RequestMapping("/contract/contractFile")
public class ContractFileController extends BaseController
{
    private String prefix = "contract/contractFile";

    @Autowired
    private IContractFileService contractFileService;

    @GetMapping()
    public String contractFile()
    {
        return prefix + "/contractFile";
    }

    /**
     * 查询合同附件列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractFile contractFile)
    {
        startPage();
        List<ContractFile> list = contractFileService.selectContractFileList(contractFile);
        return getDataTable(list);
    }

    /**
     * 导出合同附件列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractFile contractFile)
    {
        List<ContractFile> list = contractFileService.selectContractFileList(contractFile);
        ExcelUtil<ContractFile> util = new ExcelUtil<ContractFile>(ContractFile.class);
        return util.exportExcel(list, "合同附件数据");
    }

    /**
     * 新增合同附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合同附件
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractFile contractFile)
    {
        return toAjax(contractFileService.insertContractFile(contractFile));
    }

    /**
     * 修改合同附件
     */
    @GetMapping("/edit/{contractFileId}")
    public String edit(@PathVariable("contractFileId") Long contractFileId, ModelMap mmap)
    {
        ContractFile contractFile = contractFileService.selectContractFileByContractFileId(contractFileId);
        mmap.put("contractFile", contractFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存合同附件
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractFile contractFile)
    {
        return toAjax(contractFileService.updateContractFile(contractFile));
    }

    /**
     * 删除合同附件
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractFileService.deleteContractFileByContractFileIds(ids));
    }
}
